In a section report, you can modify your data source at run time. Follow the steps below to connect your report to the NWind.mdb sample database at run time.
To write the code in Visual Basic
The following example shows what the code for the function looks like.
Visual Basic.NET code. Paste below the Imports GrapeCity.ActiveReports statement at the top of the code view. |
Copy Code
|
---|---|
Imports System Imports Microsoft.Win32 |
This creates a function for getDatabasePath.
Visual Basic.NET code. Paste inside the getDatabasePath function. |
Copy Code
|
---|---|
Private Function getDatabasePath() As String |
To write the code in C#
The following example shows what the code for the function looks like.
C# code. Paste below the using GrapCity.ActiveReports statement at the top of the code view. |
Copy Code
|
---|---|
using Microsoft.Win32; using System; |
This creates a function for getDatabasePath.
C# code. Paste BELOW the getDatabasePath function. |
Copy Code
|
---|---|
private string getDatabasePath() |
To write the code in Visual Basic.NET
The following example shows what the code for the method looks like.
Visual Basic.NET code. Paste above the ReportStart event. |
Copy Code
|
---|---|
Dim conn As System.Data.OleDb.OleDbConnection Dim reader As System.Data.OleDb.OleDbDataReader |
Visual Basic.NET code. Paste inside the ReportStart event. |
Copy Code
|
---|---|
Dim dbPath As String = getDatabasePath() Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath + "\NWIND.mdb" conn = New System.Data.OleDb.OleDbConnection(connString) Dim cmd As New System.Data.OleDb.OleDbCommand("SELECT * FROM Products WHERE UnitPrice = 18", conn) conn.Open() reader = cmd.ExecuteReader() Me.DataSource = reader |
To write the code in C#
The following example shows what the code for the method looks like.
C# code. Paste above the ReportStart event. |
Copy Code
|
---|---|
private static System.Data.OleDb.OleDbConnection conn; private static System.Data.OleDb.OleDbDataReader reader; |
C# code. Paste inside the ReportStart event. |
Copy Code
|
---|---|
string dbPath = getDatabasePath(); string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath + "\\NWIND.mdb"; conn = new System.Data.OleDb.OleDbConnection(connString); System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("SELECT * FROM Products WHERE UnitPrice = 18", conn); conn.Open(); reader = cmd.ExecuteReader(); this.DataSource = reader; |
To write the code in Visual Basic
The following example shows what the code for the method looks like.
Visual Basic.NET code. Paste inside the ReportEnd event. |
Copy Code
|
---|---|
reader.Close() conn.Close() |
To write the code in C#
The following example shows what the code for the method looks like.
C# code. Paste inside the ReportEnd event. |
Copy Code
|
---|---|
reader.Close(); conn.Close(); |